package web.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class AdminBaseServlet extends HttpServlet {
	
	protected void checkAdminSign(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		
		UserService userService = UserServiceFactory.getUserService();
		
		if (!userService.isUserLoggedIn() || !userService.isUserAdmin()) {
			resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
		}

	    req.setAttribute("currentUser", userService.getCurrentUser());
	}
}
